from django.db import models

# Create your models here.
from management.models import BaseModel


# 流程节点表
class NodeModel(BaseModel):
    flow_id = models.BigIntegerField(verbose_name="所属流程id")
    staff_id = models.BigIntegerField(verbose_name="审批人id")

    class Meta():
        db_table = "flow_check_tb"
        verbose_name = "流程审批人表"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.flow_id


# 流程模板表
class FlowTemplateModel(BaseModel):
    name = models.CharField(verbose_name="流程名称", max_length=30)
    class Meta():
        db_table="flow_template_tb"
        verbose_name = "流程模板表"
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.name


# 节点必填项表
class NodeNeedModel(BaseModel):
    flow_template_id = models.BigIntegerField(verbose_name="所属模板id")
    name = models.CharField(verbose_name="必填项", max_length=64)
    type_id = models.BigIntegerField(verbose_name="选项类型id")
    class Meta():
        db_table="node_need_tb"
        verbose_name = "节点必填项表"
        verbose_name_plural = verbose_name
    def __str__(self):
        return f"节点id{self.flow_template_id}必填项{self.name}"


# 节点必填项类型表
class NeedTypeModel(BaseModel):
    name = models.CharField(verbose_name="类型名称", max_length=30)
    class Meta():
        db_table="need_type_tb"
        verbose_name = "必填项类型表"
        verbose_name_plural = verbose_name
    def __str__(self):
        return f"{self.name}"


# 节点必填项选项表
class NeedOptionModel(BaseModel):
    name = models.CharField(verbose_name="选项名称", max_length=30)
    need_id = models.BigIntegerField(verbose_name="选项类型id")
    class Meta():
        db_table="need_option_tb"
        verbose_name = "必填项选项表"
        verbose_name_plural = verbose_name
    def __str__(self):
        return f"{self.name}"


# 流程模板表
class FlowModel(BaseModel):
    name = models.CharField(verbose_name="流程名称", max_length=30)
    is_use = models.BooleanField(verbose_name="是否启用")
    flow_tamplate_id = models.BigIntegerField(verbose_name="模板表")
    desc = models.CharField(verbose_name="简介", max_length=256, null=True, blank=True)
    class Meta():
        db_table="flow_tb"
        verbose_name = "流程模板表"
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.name


# 流程节点实例表
class NewNodeModel(BaseModel):
    STATUS = (
        (0, "审批失败"),
        (1, "待审批"),
        (2, "审批中"),
        (3, "审批通过"),
        (4, "驳回"),
        (5, "已撤回"),
    )
    new_flow_id = models.BigIntegerField(verbose_name="审批实例id")
    status = models.SmallIntegerField(verbose_name="节点状态", choices=STATUS, default=1)
    staff_id = models.BigIntegerField(verbose_name="审批人id", null=True, blank=True)
    remarks = models.CharField(verbose_name="备注", max_length=256, null=True, blank=True)
    class Meta():
        db_table="new_node_tb"
        verbose_name = "流程节点实例表"
        verbose_name_plural = verbose_name
    def __str__(self):
        return f"审批节点{self.new_flow_id}"


# 节点信息表
class NewNodeNeedModel(BaseModel):
    new_flow_id = models.BigIntegerField(verbose_name="实例节点id")
    need_id = models.BigIntegerField(verbose_name="必填项id")
    need = models.CharField(verbose_name="内容", max_length=256)
    class Meta():
        db_table="new_node_need_tb"
        verbose_name = "节点信息表"
        verbose_name_plural = verbose_name
    def __str__(self):
        return f"节点id{self.new_flow_id}必填项{self.need_id}"


# 流程实例表
class NewFlowModel(BaseModel):
    STATUS = (
        (0, "审批失败"),
        (1, "待提交"),
        (2, "审批中"),
        (3, "审批成功"),
        (4, "驳回"),
        (5, "已撤回"),
    )
    staff_id = models.BigIntegerField(verbose_name="发起人")
    flow_id = models.BigIntegerField(verbose_name="发起流程id")
    status = models.SmallIntegerField(verbose_name="审批状态", choices=STATUS, default=1)
    end_date = models.DateTimeField(verbose_name="完成时间", null=True, blank=True)
    class Meta():
        db_table="new_flow_tb"
        verbose_name = "流程实例表"
        verbose_name_plural = verbose_name
    def __str__(self):
        return f"发起人{self.staff_id}，发起流程{self.flow_id}"